package com.brian.desktools

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.brian.desktools.features.BinaryConversionScreen
import com.brian.desktools.features.CalculatorScreen
import com.brian.desktools.features.TimeFormatScreen
import desktools.composeapp.generated.resources.*
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
@Preview
fun MainScreen(onTabChanged: (TabItem)->Unit = {}) {
    val list: List<TabItem> = listOf(
        TabItem( stringResource(Res.string.binary_conversion_title)) { BinaryConversionScreen() },
        TabItem(stringResource(Res.string.calculator_title)) { CalculatorScreen() },
        TabItem(stringResource(Res.string.time_title)) { TimeFormatScreen() },
    )
    val currTab = remember { mutableStateOf(list[0]) }
    MaterialTheme {
        Row {
            Column(modifier = Modifier.weight(0.3f)) {
                list.forEach { item ->
                    Row(
                        modifier = Modifier.fillMaxWidth().height(48.dp)
                            .background(color = if (item == currTab.value) Color(0xFFD1D1D1) else Color.Transparent)
                            .padding(start = 10.dp)
                            .clickable {
                                currTab.value = item
                                onTabChanged(item)
                            },
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Text(text = item.title)
                    }
                }
            }
            Column(modifier = Modifier.weight(0.7f)) {
                currTab.value.content()
            }
        }
    }
}


data class TabItem(val title: String, val content: @Composable () -> Unit)